﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace LearnDrive
{
    public partial class frmPro : Form
    {
        private int typekm;
        private int typelx;
        private int mysucheng = 1;
        private Color cc = Color.Red;
        private Color cp = Color.Black;
        private int myjichu = 1;
        private int isWenMang = 0;
        private const int SB_HORZ = 0;
    private const int SB_VERT = 1;
    private const int SB_CTL  = 2;
    private const int SB_BOTH = 3;
    [DllImport("user32.dll")]
    public static extern int ShowScrollBar(IntPtr hWnd, int iBar, int bShow);
    private DataSet dsinfo;
    private int curinfo;
    private int infonum;
        public frmPro(int km,int lx)
        {
            InitializeComponent();
            typekm = km;
            typelx = lx;
        }

        private void frmPro_Load(object sender, EventArgs e)
        {
            dsinfo = AShelp.getInfo();
            if (dsinfo != null)
            {
                infonum = dsinfo.Tables[0].Rows.Count;
                if (infonum > 0)
                {
                    curinfo = 0;
                    textBox1.Text = dsinfo.Tables[0].Rows[curinfo]["NeiRong"].ToString();
                }
            }
            
            //AShelp.Play("sysvoice\\简介.mp3");
            button4_Click(null, null);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "不收听")
            {
                AShelp.Stop();
                button1.Text = "收听";
            }
            else
            {
                //AShelp.Play("sysvoice\\简介.mp3");
                button1.Text = "不收听";
            }
        }

        private void frmPro_FormClosing(object sender, FormClosingEventArgs e)
        {
            AShelp.Stop();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            mysucheng =1;            
            button5.ForeColor = cc;
            button4.ForeColor = cp;
            button17.Visible = true;
            button18.Visible = true;
            button6.Visible = false;
            button7.Visible = false;
            button8.Visible = false;
            button9.Visible = false;
            if (MySelect.typekm == "恢复驾照" && MySelect.typelx == "DEF")
            {
                button19.Visible = true;
                button20.Visible = true;
            }
            else
            {
                button19.Visible = false;
                button20.Visible = false;

            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            mysucheng = 0;
            button4.ForeColor = cc;
            button5.ForeColor = cp;
            button17.Visible = false;
            button18.Visible = false;
            button6.Visible = true;
            button7.Visible = true;
            button8.Visible = true;
            button9.Visible = true;
            button19.Visible = false;
            button20.Visible = false;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            gettitle(sender);
            myjichu = 1;
            MySelect.zhangjie = "基础练习";
            setNocolor(); 
            button6.ForeColor = cc;
            getlist();
        }
        private void gettitle(object sender)
        { 
            Button b=sender as Button;
            if (b != null)
                groupBox1.Text = "选择－" + b.Text;
        }
        private void getlist()
        {
            int KeMu1 = 0, KeMu4 = 0, HuiFu = 0;
            if (typekm == 1) KeMu1 = 1;
            else if (typekm == 4) KeMu4 = 1;
            else if (typekm == 5) HuiFu = 1;
            int cccc = 0, aab = 0,ab = 0, def = 0;
            if (typelx == 1) cccc = 1;
            else if (typelx ==2) aab = 1;
            else if (typelx == 3) ab = 1;
            else if (typelx ==4) def = 1;
            int sucheng = 0;
            if (mysucheng == 1) sucheng = 1;            
            int jichu = 0, qianghua = 0, zhuanxiang = 0, zhangjie = 0;
            if (myjichu == 1) jichu = 1;
            else if (myjichu == 3) zhuanxiang = 1;
            else if (myjichu == 2) qianghua = 1;
            else if (myjichu == 4) zhangjie = 1;
            getDSList(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def, sucheng, jichu, qianghua, zhuanxiang, zhangjie);

        }

        private void getDSList(int KeMu1, int KeMu4, int HuiFu, int cccc, int aab, int ab, int def, int sucheng, int jichu, int qianghua, int zhuanxiang, int zhangjie)
        {
            DataSet ds = AShelp.getList(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def, sucheng, jichu, qianghua, zhuanxiang, zhangjie, isWenMang);

            if (listBox1.Items.Count > 0)
            {
                //清空所有项
                listBox1.Items.Clear();
            }
            if (ds != null)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    listBox1.Items.Add(ds.Tables[0].Rows[i]["BianHao"].ToString() + "-" + ds.Tables[0].Rows[i]["MingCheng"].ToString());
                }
            }
            else
            {
                MessageBox.Show("没有这个栏目的数据！");
            }
            button12.Enabled = false;
            button13.Enabled = false;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            gettitle(sender);
            myjichu = 1;
            MySelect.zhangjie = "基础模拟";
            setNocolor();            
            button7.ForeColor = cc;
            MySelect.zhangjie_s = "";
            MySelect.codebm = "";
            //MySelect.type = "moni";
            MySelect.Isjichu = 1;
            frmShow f = new frmShow(typelx, "", "moni");
            f.ShowDialog();
        }
        private void setNocolor()
        {
            button6.ForeColor = cp;
            button7.ForeColor = cp;
            button8.ForeColor = cp;
            button9.ForeColor = cp;
            button10.ForeColor = cp;
            button14.ForeColor = cp;
            button15.ForeColor = cp;
            button17.ForeColor = cp;
            button18.ForeColor = cp;
            button19.ForeColor = cp;
            button20.ForeColor = cp;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            gettitle(sender);
            myjichu =2;
            MySelect.zhangjie = "强化练习";
            setNocolor();            
            button8.ForeColor = cc;
            getlist();            
        }

        private void button9_Click(object sender, EventArgs e)
        {
            //MySelect.type = "moni";
            gettitle(sender);
            myjichu = 2;
            MySelect.zhangjie = "强化模拟";
            setNocolor(); 
            button9.ForeColor = cc;
            MySelect.Isqianghua = 1;
            frmShow f = new frmShow(typelx, "", "moni");
            f.ShowDialog();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            gettitle(sender);
            myjichu =3;
            MySelect.zhangjie = "专项加强";
            setNocolor(); 
            button10.ForeColor = cc;
            getlist();
        }

        private void button14_Click(object sender, EventArgs e)
        {
            //MySelect.type = "moni";
            gettitle(sender);
            myjichu = 3;
            MySelect.zhangjie = "专项模拟";
            setNocolor(); 
            button14.ForeColor = cc;
            MySelect.Iszhuanxiang = 1;
            frmShow f = new frmShow(typelx, "", "moni");
            f.ShowDialog();
            
        }

        private void button15_Click(object sender, EventArgs e)
        {
            gettitle(sender);
            myjichu = 4;
            MySelect.zhangjie = "章节练习";
            setNocolor(); 
            button15.ForeColor = cc;
            getlist();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                string code = listBox1.SelectedItem.ToString();
                string codebm = code.Split('-')[0];
                MySelect.zhangjie_s = code.Split('-')[1].Trim();
                MySelect.codebm = codebm;
                MySelect.isrand = true;
                //frmShow f = new frmShow(typelx,codebm,"random");
                //f.ShowDialog();
                Random r = new Random();
                int i = r.Next(60);
                MySelect.changci = i.ToString("000");
                if (MySelect.typekm == "恢复驾照" && MySelect.typelx == "DEF" && MySelect.zhangjie == "速成练习")
                {
                    frmStudyWM f = new frmStudyWM();
                    f.ShowDialog();

                }
                else
                {
                    frmStudy f = new frmStudy();
                    f.ShowDialog();
                }
            }
        }

        private void listBox1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                button12.Enabled = true;
                button13.Enabled = true;
            }

        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                string code = listBox1.SelectedItem.ToString();
                string codebm = code.Split('-')[0];
                MySelect.zhangjie_s = code.Split('-')[1].Trim();
                MySelect.codebm = codebm;
                MySelect.isrand = false;                
                Random r = new Random();
                int i = r.Next(60);
                MySelect.changci = i.ToString("000");
                if (MySelect.typekm == "恢复驾照" && MySelect.typelx == "DEF" && MySelect.zhangjie.Contains("文盲"))
                {
                    frmStudyWM f = new frmStudyWM();
                    f.ShowDialog();

                }
                else
                {
                    frmStudy f = new frmStudy();
                    f.ShowDialog();
                }
                //frmStudy f = new frmStudy();
                //f.ShowDialog();
            }
        }

        private void button17_Click(object sender, EventArgs e)
        {
            gettitle(sender);
            MySelect.zhangjie = "速成练习";
            setNocolor();
            button17.ForeColor = cc;
            myjichu = 0;
            getlist();
        }

        private void button18_Click(object sender, EventArgs e)
        {
            gettitle(sender);
            MySelect.Issucheng = 1;
            MySelect.zhangjie = "速成模拟";
            setNocolor();
            //MySelect.type = "moni";
            button18.ForeColor = cc;
            frmShow f = new frmShow(typelx, "", "moni");
            f.ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (curinfo > 0)
            {
                curinfo--;
                textBox1.Text = dsinfo.Tables[0].Rows[curinfo]["NeiRong"].ToString();
            }
            else
            {
                MessageBox.Show("已经是第一条了！");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (curinfo < infonum - 1)
            {
                curinfo++;
                textBox1.Text = dsinfo.Tables[0].Rows[curinfo]["NeiRong"].ToString();
            }
            else
            {
                MessageBox.Show("已经是最后一条了！");
            }
        }

        private void button11_Click(object sender, EventArgs e)
        {
            int count = AShelp.getCTCount();
            if (count == 0)
            {
                MessageBox.Show("您还没有错题！");
            }
            else
            {
                //MySelect.type = "cuoti";
                frmStudy f = new frmStudy("cuoti");
                f.ShowDialog();

            }
        }

        private void button16_Click(object sender, EventArgs e)
        {            
            frmShow f = new frmShow(typelx, "", "fangzhen");
            f.ShowDialog();
        }

        private void 设置选项随机比例ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmRand f = new frmRand();
            f.ShowDialog();
        }

        private void button19_Click(object sender, EventArgs e)
        {
            gettitle(sender);
            MySelect.zhangjie = "科目一文盲";
            setNocolor();
            button19.ForeColor = cc;
           
                frmWMpwd f = new frmWMpwd(1);
                if (f.ShowDialog() != DialogResult.Yes)
                {
                    return;
                }
                else
                {
                    isWenMang = 1;
                    getDSList(1, 0, 0, 0, 0, 0, 0,0, 0, 0, 0,0);
                    isWenMang = 0;
                }
            
        }

        private void button20_Click(object sender, EventArgs e)
        {
            gettitle(sender);
            MySelect.zhangjie = "科目四文盲";
            setNocolor();
            button20.ForeColor = cc;
            
                frmWMpwd f = new frmWMpwd(2);
                if (f.ShowDialog() != DialogResult.Yes)
                {
                    return;
                }
                else
                {
                    isWenMang = 1;
                    getDSList(0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                    isWenMang = 0;
                }
            
        }
    }
}
